package org.springblade.modules.admin.controller.openapi;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.dto.openapi.HtDaySearchCondition;
import org.springblade.modules.admin.dto.openapi.HtUserPlanSearchDTO;
import org.springblade.modules.admin.service.IMaintainSignService;
import org.springblade.modules.admin.vo.openapi.HtUserPlanVO;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: Sharry
 * @createTime: 2025-08-07 8:52
 * @version: Version-1.0
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/openapi/htCalculate")
@Api(value = "高温补贴工单查询接口", tags = "高温补贴工单查询接口")
public class HtCalculateOpenAPIController {

	private final IMaintainSignService signService;

	/**
	 * 根据时间集合查询维保/保养工单
	 * @return 结果
	 */
	@PostMapping("/plan/by/date")
	@ApiOperation("根据日期集合，查询几个主要类型工单，主要为维修、保养；其他类型工单，预留空间")
	@ApiOperationSupport(order = 1)
	public R<List<HtUserPlanVO>> searchByDate(@RequestBody HtUserPlanSearchDTO searchDTO) {
		// 1. 查询查询条件判断
		if(Func.isEmpty(searchDTO) || Func.isEmpty(searchDTO.getDaySearchConditions())){
			log.warn("中研部高温补贴支援接口，查询梯无忧指定时间区间内人员-工单，参数为空");
			return R.data(new ArrayList<>());
		}
		// 2. 拆分请求，获取结果
		List<HtUserPlanVO> resultList = new ArrayList<>();
		List<HtDaySearchCondition> daySearchConditions = searchDTO.getDaySearchConditions();
		daySearchConditions.forEach(d -> resultList.addAll(signService.getHtUserPlanByTimeCondition(d)));
		return R.data(resultList);
	}

}
